
#include "local-image.h"

using namespace localimg;

Bool localimg::sendLocalImage(Interface<ICrossTransmitter> transmitter, UInt localImageChannel/* 0~7 */, ShortTimestamp timestamp, ImagePointer image)
{
    if (transmitter.isNull()) return FALSE;
    if (localImageChannel >= 8) return FALSE;
    if (!timestamp.session.isValid()) return FALSE;
    if (timestamp.offset <= 0) return FALSE;
    if (!image.isValid()) return FALSE;
    if (!image.isColor()) return FALSE;
    if (image.getData().isEmpty()) return FALSE;

    Binary bin(48 + image.getHeight() * image.getRowBytes(), 0);
    *(UInt*)&bin[0] = localImageChannel;
    *(UInt*)&bin[4] = image.getWidth();
    *(UInt*)&bin[8] = image.getHeight();
    *(UInt*)&bin[12] = image.getRowBytes();
    *(Double*)&bin[16] = timestamp.offset;

    Binary sessionBin = timestamp.session.toString().toBinary();
    utility::memoryCopy(sessionBin.data(), &bin[24], sessionBin.size());

    utility::memoryCopy(image.getData().data(), &bin[48], image.getData().size());

    return transmitter->sendToNative("LocalImageInput", "LocalImageV1", bin);
}